< previous page page_324 next page >

Page 324
Using the Microsoft Jet Database Methods
The two database-related Workspace methods are CreateDatabase and OpenDatabase. You use the CreateDatabase method to create a new database, and you use the OpenDatabase method to open an existing database.
Let's first add a command button to create a new database. Set the button's Name property to cmdCreateDB and its Caption property to CreateDB. Add the code in Listing 9.8 to the cmdCreateDB_Click code window.
Type.gifListing 9.8. Coding the cmdCreateDB_Click event.
Private Sub cmdCreateDB_Click()
    '
    ' create a new database
    '
    On Error Resume Next
    '
    Dim dbOne As Database
    Dim dbTwo As Database
    Dim ws As Workspace
    Dim dbTemp As Database
    '
    Dim strDBNameOne As String
    Dim strDBNameTwo As String
    Dim strWSName As String
    Dim strWSUser As String
    Dim strWSPassword As String
    Dim strMsg As String
    '
    ' init vars
    strDBNameOne = App.Path & "\CreateDBOne.mdb"
    strDBNameTwo = App.Path & "\CreateDBTwo.mdb"
    strWSName = App.EXEName
    strWSUser = "admin"
    strWSPassword = ""
    '
    ' erase dbs if they exist
    Kill strDBNameOne
    Kill strDBNameTwo
    '
    ' create workspace
    Set ws = DBEngine.CreateWorkspace(strWSName, strWSUser, strWSPassword)
    '
    ' create new jet db
    Set dbOne = ws.CreateDatabase(strDBNameOne, dbLangGeneral, dbVersion30)
    Set dbTwo = ws.CreateDatabase(strDBNameTwo, dbLangGeneral, dbVersion30)
    '
    ' now show db collection
    For Each dbTemp In ws.Databases
        strMsg = strMsg & "Name: " & dbTemp.Name & vbCrLf

 
< previous page page_324 next page >

If you like this book, buy it!